#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct student {
    int chinese, math, english, total, id;
    student(int a, int b, int c, int d): chinese(a), math(b), english(c), id(d){
        total = a + b + c;
    }
};
bool compare(student& a, student& b) {
    if(a.total != b.total) return a.total > b.total;
    if(a.chinese != b.chinese) return a.chinese > b.chinese;
    return a.id < b.id;
}
int main() {
    int n;
    cin >> n;
    vector<student> a;
    for(int i = 1; i <= n; i++) {
        int c, m, e;
        cin >> c >> m >> e;
        a.push_back(student(c, m, e, i));
    }
    sort(a.begin(), a.end(), compare);
    for(int i = 0; i < 5; i++) {
        student s = a[i];
        cout << s.id << " " << s.total << endl;
    }
    return 0;
}